package com.example.demomybatis.service.impl;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.example.demomybatis.entity.Student;
import com.example.demomybatis.mapper.StudentMapper;
import com.example.demomybatis.service.IStudentService;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhaoheng
 * @since 2023-07-08
 */
@Service
public class StudentServiceImpl extends MppServiceImpl<StudentMapper, Student> implements IStudentService {
    @Resource
    StudentMapper studentMapper;

    @Override
    public List<Student> queryByNames(List<String> names) {
        return studentMapper.queryByNames(names);
    }

    @Override
    public String updateBirthday(String id, String birthday) {
        Student student = this.getById(id);
        LocalDateTime dateTime = LocalDateTimeUtil.parse(birthday, DatePattern.PURE_DATETIME_PATTERN);
        student.setBirthday(dateTime);
        boolean b = this.saveOrUpdate(student);
        return String.valueOf(b);
    }
}
